package cn.web.management.web.servlet.inform.user;

import cn.web.management.domain.PersonalInform;
import cn.web.management.service.impl.FindEmployImpl;
import cn.web.management.service.inface.FindEmploy;
import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.Map;

@WebServlet(name = "personalInformServlet", value = "/personalInformServlet")
public class personalInformServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    /**
     * @description: 获取用户个人信息
     * @paramName: [req, resp]
     * @paramType: [javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse]
     * @returnType: void
     */
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/json;charset=UTF-8");
        FindEmploy personalInform = new FindEmployImpl();
        HttpSession session = req.getSession();
        String employno = (String)session.getAttribute("employno");
        Map<String, Object> employ = personalInform.findEmploy(employno);
        ObjectMapper mapper = new ObjectMapper();

        mapper.writeValue(resp.getWriter(),employ);
    }
}
